package com.Tjise.equals;

public class Student {
    public static void main(String[] args) {
        //实例化对象
        Student1 student1 = new Student1("王俊杰");
        Student1 student2 = new Student1("王伟");
        System.out.println("两人是否一样："+student1.equals(student2));
    }

   public static class Student1{
       /**
        * 成员变量-姓名
        */
       String name;

       public String getName() {
           return name;
       }

       public void setName(String name) {
           this.name = name;
       }

       public Student1() {
       }

       public Student1(String name) {
           this.name = name;
       }

       /**
        * equals判断两个变量是否相同
        * @param stu
        * @return
        */
       public boolean equals(Object stu){
           if(this == stu){
               return true;
           }
           if (stu instanceof Student1) {
            Student1 astudent = (Student1) stu;
               if (astudent.getName().equals(this.name)){
                   return true;
               }
           }
           return false;
       }

   }
}
